<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
      + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<!-- 下拉框 -->
<link rel="stylesheet" href="static/ace/css/chosen.css" />

<link href="plugins/kindeditor/themes/simple/simple.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="static/ace/css/datepicker.css" />
<link href="//cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet">
<!-- jsp文件头和头部 -->
<%@ include file="../index/top.jsp"%>
<style>
.disabled{color:#000;cursor: default;}
.disabled:hover{color:#000;text-decoration:none;}
</style>
</head>
<body class="no-skin">
  <!-- /section:basics/navbar.layout -->
  <div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
      <div class="main-content-inner">
        <div class="page-content">
          <div class="row">
            <div class="col-xs-12">
              <form action="period/${msg }.do" name="goodsForm"
                id="goodsForm" method="post">
                <input type="hidden" name="goods_id" id="goods_id"/>
                <div id="zhongxin" style="padding-top: 13px;">
                  <table id="table_report"
                    class="table table-striped table-bordered table-hover">
                    <tr>
                    <td
                        style="width: 100px; text-align: right; padding-top: 13px;">商品期次:</td>
                      <td colspan="1"><input type="text" name="time"
                        id="time" value="${goods.time }"
                        maxlength="32" placeholder="这里输入商品期次" title="商品期次"
                        style="width: 98%;" /></td>
                     </tr>
                      <tr>
                       <td
                        style="width: 100px; text-align: right; padding-top: 13px;">零售价:</td>
                      <td colspan="1"><input type="number" name="price"
                        id="price" value="${goods.price }"
                        maxlength="11" min="0" placeholder="这里输入零售价" title="零售价"
                        style="width: 98%;" />
                        </td>
                        </tr>
                     <tr>
                      <td
                        style="width: 30px; text-align: right; padding-top: 13px;">销售时间:</td>
                      <td><span class="dib vm">上架时间:&nbsp;</span><input
                        id="startTime" name="startTime"
                        placeholder="请选择上架时间"
                        value="${goods.startTime }" />&emsp;&emsp; <span
                        class="dib vm">下架时间 :&nbsp;</span><input
                        class="dib vm" id="endTime" name="endTime"
                        placeholder="请选择下架时间 " value="${goods.endTime }" /></td>
                    </tr>
                     <tr>
                      <td
                        style="width: 85px; text-align: right; padding-top: 10px;">选择基地:</td>
                      <td><select  name="base_id" id="base_id" data-placeholder="选择基地"
                        style="vertical-align: top;width: 98%;">
                          <c:forEach var="co" varStatus="i" items="${baseList}">
                            <option value="${co.id }" <c:if test='${goods.unit == co.unit}'>selected=selected</c:if>>${co.name}</option>
                          </c:forEach>
                      </select>
                      <!--  -->
                      </td>
                    </tr>
                    <tr>
                        <td
                          style="width: 85px; text-align: right; padding-top: 10px;">选择商品:</td>
                        <td><a href="javascript:void(0)" id="selectGoods">添加商品</a>&nbsp;
                          <span id="gS"></span>
                        </td>
                      </tr>
                  </table>
                   <table id="table_report1"
                    class="table table-striped table-bordered table-hover">
                       <tr>
                        <td style="text-align: center;" colspan="10">
                        <c:if test="${state!=00 }">
                          <a class="btn btn-mini btn-primary"
                          onclick="save();">下一步</a>
                        </c:if>
                           <a class="btn btn-mini btn-danger"
                          onclick="top.Dialog.close();">取消</a>
                        </td>
                      </tr>
                    </table>
                </div>
                <div id="zhongxin2" class="center" style="display: none">
                  <br /> <br /> <br /> <br /> <img
                    src="static/images/jiazai.gif" /><br />
                  <h4 class="lighter block green"></h4>
                </div>
              </form>
            </div>
            <!-- /.col -->
          </div>
          <!-- /.row -->
        </div>
        <!-- /.page-content -->
      </div>
    </div>
    <!-- /.main-content -->
  </div>


  <!-- /.main-container -->
  <!-- basic scripts -->
  <!-- 页面底部js¨ -->
  <%@ include file="../index/foot.jsp"%>
  <!-- ace scripts -->
  <script src="static/ace/js/ace/ace.js"></script>
  <!-- inline scripts related to this page -->
  <!-- 下拉框 -->
  <script src="static/ace/js/chosen.jquery.js"></script>
  <!--提示框-->
  <script type="text/javascript" src="static/js/jquery.tips.js"></script>
  <script type="text/javascript" src="static/js/common/file_upload.js"></script>
  <script type="text/javascript" src="plugins/kindeditor/kindeditor-all.js"></script>
  <script type="text/javascript" src="plugins/kindeditor/lang/zh_CN.js"></script>
  <script type="text/javascript" src="static/laydate/laydate.js"></script>
  <script type="text/javascript" src="static/js/provincial.municipal.league.js"></script>
</body>
<script type="text/javascript">
  $(top.hangge());
  var itemAddEditor ;
  var currentIndex = 0;
  //页面初始化完毕后执行此方法
  var min_ratio=$("#min_ratio").val();
  var max_ratio=$("#max_ratio").val();
  
  
  

  function save(){
	  var goods_id=$("#goods_id").val();
	  var time=$("#time").val();
	  var price=$("#price").val();
	  var base_id=$("#base_id").val();
	  var base = $("#base_id  option:selected").text();
	  var startTime=$("#startTime").val();
	  var endTime=$("#endTime").val();
	  if($.trim(time)==""){
          alert("请填写商品期次！");
          return false;
        }
	 	if($.trim(price)==""){
	          alert("请输入商品零售价!");
	          return false;
	    }
	  if($.trim(startTime)==""){
          alert("请选择商品上架时间！");
          return false;
        }
	  if($.trim(endTime)==""){
          alert("请选择商品下架时间！");
          return false;
        }
	   	if($.trim(goods_id)==""){
          alert("请选择商品！");
          return false;
        }
	   	$.ajax({
			type: "POST",
			url: '<%=basePath%>period/saveGoodsTime.do',
	    	data: {'goods_id':goods_id,'base_id':base_id,'time':time,'startTime':startTime,'endTime':endTime,'price':price},
			success: function(data){
				
				var timeId=data.substring(7,data.length);
			    if("success"==data.substring(0,7)){
			    	  top.jzts();
			    	   	 var diag = new top.Dialog();
			    	   	 diag.Drag=true;
			    	   	 diag.Title ="期次商品信息";
			    	   	 diag.URL = '<%=basePath%>period/goodsGoodsTime.do?goods_id='+goods_id+'&base_id='+base_id+'&timeId='+timeId;
			    	   	 diag.Width = 1200;
			    	   	 diag.Height = 800;
			    	   	 diag.CancelEvent = function(){ //关闭事件
			    	   	
			    	   		diag.close();
			    	   		top.Dialog.close();
			    	   	 };
			    	   	 diag.show();
			   }else if("exist"==data){
				   alert(base+"基地该商品期次已存在!");
			   }else{
				   alert("新增期次商品失败，稍后重试！");
			   }
			    
			}
		});
  }
  $("#selectGoods").on("click",function(){
	 var time=$("#time").val();
	 var base_id=$("#base_id").val();
	 var goods_id= $("#goods_id").val();
	 if(time == ""){
		 alert("请输入商品期次!");
		 return false;
	 }
     var diag = new top.Dialog();
     diag.Drag=true;
     diag.Title ="选择商品";
     diag.URL = '<%=basePath%>period/selectGoodsList.do?goods_id='+goods_id+'&time='+time+'&base_id='+base_id;
    diag.Width = 800;
    diag.Height = 420;
    diag.CancelEvent = function() {
      diag.close();
    }, diag.OKEvent = function() {
      var child = diag.innerFrame.contentWindow.document;
      $("#goods_id").val($(child).find("#ids").val());
      $("#gS").html($(child).find("#title").val());
      diag.close();
    };//点击确定后调用的方法
    diag.show();
  })
  
    var startTime = {
    elem : '#startTime',
    format : 'YYYY-MM-DD hh:mm:ss',
    min : laydate.now(), //设定最小日期为当前日期
    max : '2099-06-16 23:59:59', //最大日期
    istime : true,
    istoday : true,
    choose : function(datas) {
      endTime.min = datas; //开始日选好后，重置结束日的最小日期
      endTime.start = datas //将结束日的初始值设定为开始日
    }
  };

  var endTime = {
    elem : '#endTime',
    format : 'YYYY-MM-DD hh:mm:ss',
    min : laydate.now(),
    max : '2099-06-16 23:59:59',
    istime : true,
    istoday : true,
    choose : function(datas) {
      startTime.max = datas; //结束日选好后，重置开始日的最大日期
    }
  };

 laydate(startTime);
  laydate(endTime);
</script>
</html>